using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.BizTalk.BaseFunctoids;
using System.Reflection;

namespace eliasen.eu.BizTalk.Functoids
{
    class IfThenElse : BaseFunctoid
    {
        public IfThenElse()
            : base()
        {
            
            //ID for this functoid
            this.ID = 6430;

            // resource assembly must be ProjectName.ResourceName if building with VS.Net
            SetupResourceAssembly("eliasen.eu.BizTalk.Functoids.eliasen.eu.BizTalk.Functoids.Resources", Assembly.GetExecutingAssembly());

            //Setup the Name, ToolTip, Help Description, and the Bitmap for this functoid
            SetName("Str_IfThenElse_Name");
            SetTooltip("Str_IfThenElse_Tooltip");
            SetDescription("Str_IfThenElse_Description");
            SetBitmap("Bmp_IfThenElse_Icon");

            this.SetMinParams(3);
            this.SetMaxParams(3);

            //set the function name that needs to be called when this Functoid is invoked. This means that
            //this Functoid assembly need to be present in GAC for its availability during Test..Map and Runtime.
            SetExternalFunctionName(GetType().Assembly.FullName, "eliasen.eu.BizTalk.Functoids.DateConverter", "GetConvertedDate");

            //category for this functoid. This functoid goes under the String Functoid Tab in the
            //VS.Net toolbox for functoids.
            this.Category = FunctoidCategory.String;
            this.OutputConnectionType = ConnectionType.AllExceptRecord;

            AddInputConnectionType(ConnectionType.AllExceptRecord); //first input
            AddInputConnectionType(ConnectionType.AllExceptRecord); //second input
            AddInputConnectionType(ConnectionType.AllExceptRecord); //third input
        }

        //this is the function that gets called when the Map is executed which has this functoid.
        public string GetIfThenElse(string b, string ifTrue, string ifFalse)
        {
            bool b_b = Utility.ConvertStringToBool(b, false);
            if (b_b)
            {
                return ifTrue;
            }
            else
            {
                return ifFalse;
            }
        }
    }
}
